/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*				PROJETO III - PROGRAMACAO CONCORRENTE
*							 SSC0143				  PROF.: JULIO ESTRELLA
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*	DESCRICAO:	SMOOTHING DE IMAGENS OPEN MPI E CUDA
*
*	LINGUAGEM:	C
*				
*	GRUPO - 8:	CARLOS HUMBERTO DOS SANTOS BAQUETA			  NUSP: 7987456
*	(TURMA-A)	RICARDO    ISSAMU   FUKUDA   GUNZI			  NUSP: 7986729
*				
*	
*	ENTREGA  :	07/12/2014									  BCC-012
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h> 
#include <string.h> 
#include <math.h> 
// Library that allows to use time functions to evaluate the performance
#include <sys/time.h>

#define NUMSIMUL 3

double std_deviation_calculate(double *trials, double mean){
	int i;
	double local_std_dev=0.0;
	for(i=0; i<NUMSIMUL; i++){
		local_std_dev += ((trials[i] - mean) * (trials[i] - mean))/NUMSIMUL;
	}
	return sqrt(local_std_dev);
}

double mean_calculate(double *v){
	int i;
	double local_mean = 0.0;
	for(i=0; i<NUMSIMUL; i++){
		local_mean += v[i]/NUMSIMUL;
	}
	return local_mean;
}

int main(int argc, char **argv)
{
	FILE *fseq=NULL, *fpar=NULL, *out=NULL;
	double time_start, time_end, 
			time_start_experiment, 
			time_end_experiment,
			avg_time_sequencial,
			avg_time_parallel,
			deviat_seq,
			deviat_par;
	int np, i, k, n;
	double trials_seq[NUMSIMUL];
	double trials_par[NUMSIMUL];
	double trials[NUMSIMUL],
			mean=0.0,
			stddev=0.0,
			confwidth=0.0,
			confmin=0.0,
			confmax=0.0;
	double tseqAux, tseq, tmpiAux, tmpi, tparAux;
	char *arq_name;
	if(argc > 4){
		if ((fseq = fopen(argv[1], "r")) == NULL){
          	fprintf(stderr, "Error opening outfile\n");
        }
        if ((fpar = fopen(argv[2], "r")) == NULL){
          	fprintf(stderr, "Error opening outfile\n");
        }
        n = atoi(argv[3]);
        arq_name = argv[4];
	}else{
		fprintf(stderr, "Reveja a entrada!\n");
		return;
	}


	if ((out = fopen(arq_name, "a+")) == NULL){
      	fprintf(stderr, "Error opening outfile: %s\n", arq_name);
      	return;
    }

	tseq = 0.0;
	for(i=0; i<NUMSIMUL; i++){ // Calcula a média do tempo da versao sequencial
		fscanf(fseq, "%lf", &tseqAux);
		tseq += (double)(tseqAux/(double)NUMSIMUL);
	}

	tmpi = 0.0;
	for (k=0; k<n; k++){ // Calcula a média do tempo da versao mpi
		for(i=0; i<NUMSIMUL; i++){
			fscanf(fpar, "%d\t%lf", &np, &tparAux);
			tmpi += (double)(tparAux/(double)NUMSIMUL);
		}
		printf("np = %d | tmpi = %.10f | tseq = %.10f | speedup = %.10f \n", np, tmpi, tseq, tseq/tmpi);
		fprintf(out, "%d\t%.10f\n", np, (double)tseq/tmpi);
	}

    fclose(out);

	return 0;
}





